import requests
import json
import socket
import threading

def monitor_code(code):
    t = threading.Thread(target=monitor_code_thread, args=(code,))
    t.start()

def monitor_code_thread(code):
    try:
        res = socket.gethostbyname(socket.gethostname())
        d = {"MonitorCode":str(res)+"--->"+ code}
        d = json.dumps(d)
        ret = requests.post("http://10.188.137.153:3088/MonitorCode", data=d)
    except Exception as e:
        with open(".\\Monitor.txt", "a", encoding="utf-8") as f:
            f.write(str(e))

if __name__ == '__main__':

    monitor_code("test")
    print("test11")
    import time
    time.sleep(10)

    monitor_code("test")
    time.sleep(10)

